package com.ws.test01;

import java.util.Scanner;

/**
 * @author 王硕
 * @version jdk21
 * @className Test
 * @description
 * @date 2024/11/22 15:26
 */
public class Test {
    public static void main(String[] args) {
        // 创建一个学生数组
        Student[] students = new Student[3];
        students[0] = new Student();
        students[0].setName("张三");
        students[0].setAge(20);
        students[0].setScore(85.5);
        students[1] = new Student();
        students[1].setName("李四");
        students[1].setAge(22);
        students[1].setScore(90.0);
        students[2] = new Student();
        students[2].setName("王五");
        students[2].setAge(19);
        students[2].setScore(78.5);

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学生姓名：");
        String inputName = scanner.nextLine();
        System.out.println("请输入学生年龄：");
        int inputAge = scanner.nextInt();
        boolean exists = false;
        for (Student student : students) {
            if (student.getName().equals(inputName) && student.getAge() == inputAge) {
                System.out.println("学生姓名：" + student.getName() + "，年龄：" + student.getAge() + "，成绩：" + student.getScore());
                exists = true;
                break;
            }
        }
        if (!exists) {
            System.out.println("该学生不存在");
        }
    }
}
